/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef PLOUTPUT_H
#define PLOUTPUT_H

#include <colorvga16.h>

#define COLUMNS                 80
#define LINES                   24

/**
 * The base output class.
 */
class PLOutput {
public:
	/**
	 * Constructor.
	 */
	PLOutput();
	/**
	 * Print a char at the current position and go to the
	 * next position.
	 *
	 * @param c The character to print with the attributes.
	 * @param attr Attributes for the character.
	 */
	virtual void putchar(int c, PLColorVGA16 attr) = 0;
	/**
	 * Clear the screen.
	 */
	void cls();
	/**
	 * A printf like function to print onto the screen.
	 *
	 * @param format The format of the output.
	 * @param ... The data to print.
	 */
	void printf(const char *format, ...);
	/**
	 * Print a c string to the screen.
	 *
	 * @param s The string to paint.
	 */
	void printString(char *s);
	/**
	 * Format a number into a string.
	 *
	 * @param buf The buffer in that the number was written.
	 * @param base The base to transform the number to.
	 * @param d The number.
	 */
	void itoa(char *buf, int base, int d);
	/**
	 * Move the x position of the text writing to another position.
	 *
	 * @param newX The new x position to move to.
	 */
	void moveX(int newX);
	/**
	 * Move the y position of the text writing to another position.
	 *
	 * @param newY The new y position to move to.
	 */
	void moveY(int newY);
	/**
	 * Get the width of the screen.
	 *
	 * @return The width.
	 */
	inline int width();
	/**
	 * Get the height of the screen.
	 *
	 * @return The height.
	 */
	inline int height();
	/**
	 * Get the current attributes that are set for the output.
	 *
	 * @return The current attributes.
	 */
	inline PLColorVGA16 currentAttributes();
protected:
    /**
     * Add a new line to the output.
     */
	void newline();
    /**
     * This function was executed after a clear of the output was called.
     */
	virtual void cleared() {}
    /**
     * The x position of the output screen.
     */
	int m_x;
    /**
     * The y position of the output screen.
     */
	int m_y;
    /**
     * The width of the output screen.
     */
	int m_width;
    /**
     * The height of the output screen.
     */
	int m_height;
    /**
     * The current x position of the output cursor.
     */
	int m_xpos;
    /**
     * The current y position of the output cursor.
     */
	int m_ypos;
    /**
     * The cuttent attributes that are set for the output.
     */
	PLColorVGA16 m_attr;
    /**
     * The pointer to the current used video buffer.
     */
	volatile unsigned char *m_video;
};

int PLOutput::width() {
	return m_width;
}

int PLOutput::height() {
	return m_height;
}

PLColorVGA16 PLOutput::currentAttributes() {
	return m_attr;
}

#endif
